package com.sunxu.dao;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @author 孙许
 * @date 2018-08-08
 * @description
 */
public class TestInvokerHandler implements InvocationHandler {
    /**
     * 真正的业务对象，也就是RealSubject对象
     */
    private Object target;

    public TestInvokerHandler(Object target) {
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("之前");
        Object result = method.invoke(target, args);
        System.out.println("之后");
        return result;
    }

    public Object getProxy() {
        return Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
                target.getClass().getInterfaces(), this);
    }

    public static void main(String[] args) {

    }
}
